package cn.zc.mapper;

import cn.zc.entity.*;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface StudentMapper {
    @Insert("insert into students(id, name, mypassword) values(#{id}, #{name},#{mypassword})")
    void addStudent(User user);
    @Select("select * from students where students.type =0 limit #{page},#{pageSize}")
    List<User> getStudentList(int page,int pageSize);
//    @Select("SELECT s.name, sil.student_id, sil.login_time\n" +
//            "FROM login_logs sil\n" +
//            "INNER JOIN students s ON sil.student_id = s.id;")
//    @Results({
//            @Result(property = "name", column = "name"),
//            @Result(property = "studentId", column = "student_id"),
//            @Result(property = "loginTime", column = "login_time")
//    })
    List<LoginLogVo> getLoginLog(int page,int pageSize);

    List<CourceVo> getCourcesByStudentId(String studentId);
    @Update("update student_courses set isover =1 where day_of_week =#{weekday} and period =#{period} and student_id =#{studentId}")
    void periodQiandao(Qiandao period);
    @Select("select * from student_violations where student_id =#{studentId} and violation_content=#{chidao}")
    @Results({
            @Result(property = "dayOfWeek", column = "day_of_week"),
    })
    List<LateTimeCource> overtime(String studentId,String chidao);
    /**
     * 根据学生id查询学生姓名
     */
    @Select("select name from students where id =#{studentId}")
    String getNameById(String studentId);
//    @Select("SELECT  s.name AS name, sv.*   FROM student_violations sv  LEFT JOIN  students s ON  sv.student_id=s.id limit #{page},#{pageSize};")
//    @Results({
//            @Result(property = "studentId", column = "student_id"),
//            @Result(property = "dayOfWeek", column = "day_of_week"),
//    })
    List<LateTimeCource> overtimeAll(int page,int pageSize,@Param("search") String search,int type);
    @Update("update student_courses set isover =2 where day_of_week =#{dayOfWeek} and period =#{period} and student_id =#{studentId}")
    void buqian(LateTimeCource buqianvo);
    @Update("update student_violations set violation_content ='已补签' where day_of_week =#{dayOfWeek} and period =#{period} and student_id =#{studentId} and week =#{week}")
    void setviolation(LateTimeCource buqianvo);
    @Update("UPDATE  students set uuid =#{uuid} where id =#{id}")
    void setuuid(String id, String uuid);
//    @Update("UPDATE  students set latitude =#{latitude}, longitude=#{longitude} where id =#{id}")
//    void setlocal(String latitude, String longitude,String id);
        @Select("SELECT COUNT(*)\n" +
            "FROM login_logs sil\n" +
            "INNER JOIN students s ON sil.student_id = s.id;")
    int getLoginLogNum();
        @Select("select COUNT(*) from students")
    int getStudentNum();
        @Update("update students set isonelogin =#{i} where id=#{id}")
    void setOnelogin(String id, int i);
        @Select("select * from students where id=#{id}")
    User getStudentByStudentId(String id);
        @Delete("delete from student_courses where student_courses.student_id =#{id}")
    void deleteStudentCourse(String id);
        @Update("update students set isonelogin =1 where id=#{id}")
    void resetkey(String id);
        @Delete("delete from students where id =#{userid}")
    void deleteStudent(String userid);
        @Delete("delete from student_violations where student_id =#{userid}")
    void deleteViolation(String userid);
        //删除所有迟到数据
    @Delete("delete from student_violations")
    void deleteAllViolation();
        @Delete("delete from student_courses where student_id=#{userid}")
    void deleteCource(String userid);
        @Delete("delete from login_logs where student_id=#{userid}")
    void deletelog(String userid);
}
